#include<iostream>
#include<pthread.h>
#include<unistd.h>
#include<cstdio>
#include<string>
#include<vector>
#define NUM 10
using namespace std;
struct ThreadNode 
{
    pthread_t tid;
    char namebuffer[64];
};
void *thread_routine(void* argv)
{
    int cnt = 10;
    ThreadNode* ret = (ThreadNode*)argv;
    while(cnt--)
    {
        cout<<cnt<<"  "<<ret->namebuffer<<endl;
        sleep(1);
    }
    return (void*)1234;
}
int main()
{
    vector<ThreadNode*> vv;

    for(int i = 0;i<NUM;i++)
    {
        struct ThreadNode*td = new struct ThreadNode();
        snprintf(td->namebuffer,sizeof(td->namebuffer),"threead:%d",i);
        int n = pthread_create(&td->tid,NULL,thread_routine,td);
        vv.push_back(td);
    }
    sleep(3);
    for(int i = 0;i<NUM/2;i++)
    {
        pthread_cancel(vv[i]->tid);
        cout<<"pthread_cancel "<<vv[i]->namebuffer<<" success"<<endl;
    }
    for(int i = 0;i<NUM;i++)
    {
        void* ret;
        pthread_join(vv[i]->tid,&ret);
        cout<<"thread :"<<vv[i]->namebuffer<<"  exit success exitcode:"<<(long long)ret<<endl;
    }
    return 0;
}